package core

import (
	"alertmanagerWebhook/config"
	"alertmanagerWebhook/global"
	"log"
	"os"
	"path/filepath"

	"gopkg.in/yaml.v2"
)

func InitYaml() {
	// 直接构建配置文件的路径
	dir, err := os.Getwd()
	if err != nil {
		log.Fatalln("Error getting current directory:", err)
		return
	}

	ConfigFile := filepath.Join(dir, "settings.yaml")
	c := &config.Config{}
	yamlConf, err := os.ReadFile(ConfigFile)
	if err != nil {
		log.Fatalf("get yamlconf error: %s", err)
	}
	err = yaml.Unmarshal(yamlConf, c) //yaml文件反序列化
	if err != nil {
		log.Fatalf("config init Unmarsharl: %v", err)
	}
	log.Println("config init Unmarsharl success")
	global.Config = c
}
